package models

import (
	"github.com/astaxie/beego/orm"
	"github.com/brianvoe/sjwt"
	"time"
)

type WeiXinUser struct{
	Id int
	Openid string `orm:"unique"`
	Nickname string
	Sex string
	Province string
	City string
	Country string
	Headimgurl string `orm:"type(text)"`
	Unionid string `orm:"unique"`
}

func (self *WeiXinUser)Jwt() string{
	jwtinstance := sjwt.New()
	jwtinstance.Set("Openid",self.Openid)
	jwtinstance.Set("Nickname",self.Nickname)
	jwtinstance.Set("Headimgurl",self.Headimgurl)
	jwtinstance.Set("Unionid",self.Unionid)
	jwtinstance.SetExpiresAt(time.Now().Add(time.Hour * 24 *3))
	secretKey := []byte("secret_xiegao_key")
	jwtstr := jwtinstance.Generate(secretKey)
	return jwtstr
}

func init()  {
	orm.RegisterModel(new(WeiXinUser))
}